<template>
    <div>
        <div class="container">
            <el-page-header @back="goBack" content="站点回收汇总"></el-page-header>

            <div class="e-p-b-15 e-p-t-45">
                <el-radio-group v-model="dataType" class="e-m-b-20">
                    <el-radio-button label="0">数据中台</el-radio-button>
                    <el-radio-button label="1">库存表</el-radio-button>
                    <!-- <el-radio-button label="2">学校回收情况</el-radio-button>
                    <el-radio-button label="3">入库支出</el-radio-button> -->
                    <el-radio-button label="4">回收汇总</el-radio-button>
                </el-radio-group>
                <div>
                    <el-radio-group v-model="product" class="e-m-b-45" size="mini">
                        <el-radio-button label="0">站点</el-radio-button>
                        <el-radio-button label="1">客户组/学校</el-radio-button>
                    </el-radio-group>
                </div>
                
                <div class="flex">
                    <div class="e-flex-1">
                        <el-form ref="form" :model="form" label-width="auto" style="border-bottom: 1px solid var(--light);">
                            <el-form-item label="入库时间">
                            <el-radio-group v-model="form.timeType" size="small" @input="getListStock">
                                <el-radio-button label="0">全部</el-radio-button>
                                <el-radio-button label="1">今日</el-radio-button>
                                <el-radio-button label="2">昨日</el-radio-button>
                                <el-radio-button label="3">本月</el-radio-button>
                                <el-radio-button label="4">上月</el-radio-button>
                                <el-radio-button label="5">本季度</el-radio-button>
                                <el-radio-button label="6">上季度</el-radio-button>
                                <el-radio-button label="7">本年</el-radio-button>
                                <el-radio-button label="8">上年</el-radio-button>
                                <el-radio-button label="9">自定义日期</el-radio-button>
                            </el-radio-group>
                            </el-form-item>
                            <el-form-item label="自定义日期" v-if="form.timeType == 9">
                            <el-date-picker size="small" v-model="form.date" type="daterange" range-separator="至"
                                start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="setTime"
                                :picker-options="expireTimeOPtion" :unlink-panels="true">
                            </el-date-picker>
                            </el-form-item>
                        </el-form>
                    </div>
                    <div>
                        <el-button type="primary" @click="downloadwithdrawa" plain><i class="iconfont icon-excel e-font-14 e-m-r-5"></i>导出Excel</el-button>
                    </div>
                </div>
            </div>

            <div>
                <el-table
                    :data="tableData"
                    border
                    show-summary
                    style="width: 100%">
                    <el-table-column
                        prop="name"
                        label="站点"
                        >
                    </el-table-column>
                    <el-table-column
                        prop="weight"
                        label="回收重量（KG）"
                        >
                    </el-table-column>
                    <el-table-column
                        prop="quantity"
                        label="回收件数（件）"
                        >
                    </el-table-column>
                    <el-table-column
                        prop="amount"
                        label="回收金额（元）"
                        >
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    layout: 'admin',
    head() {
        return {
            title: '站点回收汇总' 
        }
    },
    data() {
        return {
            dataType: 4,
            product: 0,
            form: {
                timeType: 3,
                date: []
            },
            tableData: [],
            expireTimeOPtion: {
                disabledDate(time) {
                    return time.getTime() > Date.now() - 8.64e6;  //如果没有后面的-8.64e6就是不可以选择今天的 
                }
            }
        }
    },
    mounted() {
        this.getListStock()
    },
    watch: {
        dataType(val) {
            if (val == 0) {
                this.$router.push({
                    path: '/'
                })
            } else if (val == 1) {
                this.$router.push({
                    path: '/inventory/list'
                })
            }
            else if (val == 2) {
                this.$router.push({
                    path: '/inventory/schoollist'
                })
            }
            else if (val == 3) {
                this.$router.push({
                    path: '/finance/receipt/receipt'
                })
            } else if (val == 4) {
                this.$router.push({
                    path: '/shop/stockTable'
                })
            }
        },
        product(val) {
            console.log(val)
            if (val == 0) {
                this.$router.push({
                    path: '/shop/stockTable'
                })
            } else if (val == 1) {
                this.$router.push({
                    path: '/enterprise/stockTable'
                })
            }
        }
    },
    methods: {
        goBack() {
            this.$router.go(-1)
        },
        getListStock(){
            // 获取站点回收量汇总
            let param = {
                timeType: this.form.timeType
            }
            if (this.form.date !== null) {
                if (this.form.date.length > 0) {
                    param.startDate = this.form.date[0]
                    param.endDate = this.form.date[1]
                }
            }
            this.$axios.post('/Store/InOrder/SumByStore',param).then((res)=>{
                this.tableData = res
            })
        },
        setTime(){
            console.log(this.form.date)
            // 选择自定义日期范围
            this.getListStock()
        },
        downloadwithdrawa() {
            //导出
            let param = {
                timeType: this.form.timeType
            }
            if (this.form.date !== null) {
                if (this.form.date.length > 0) {
                    param.startDate = this.form.date[0]
                    param.endDate = this.form.date[1]
                }
            }
            this.$axios.post('/Store/InOrder/SumByStoreDownload',
                param,
                {
                    responseType: 'blob'
                }
            ).then((res)=>{
                let content = res;
                let fileName = '站点回收汇总.xls'
                this.utils.saveAndExport(content, fileName)
            })
        }

    }
}
</script>

<style lang="scss" scoped>

</style>